package com.andy.stripes.actions;

import java.util.List;

import com.andy.stripes.domain.Article;
import com.andy.stripes.service.ArticleService;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.integration.spring.SpringBean;

/**
 * 
 * @author andy
 *
 */

public class ArticleActionBean extends AbstractActionBean {
	private static  final String VIEW_RELEASE="/release.jsp";
	private static  final String VIEW_LIST="/articles.jsp";
	private static  final String VIEW_ARTICLE="/content.jsp";
	@SpringBean
	private ArticleService articleService;
	
	
	private  Article  article=new Article();
	private  List<Article>  articles ;
	private  String  id;
	

	
	@DefaultHandler
	public  Resolution   releaseFoward()
	{		
		return new ForwardResolution(VIEW_RELEASE);		
	}

	public Resolution  insertArticle()
	{
		articleService.insertArticle(article);
		System.out.println(article.toString());
		
		articles =articleService.searchArticleList();
		return new ForwardResolution(VIEW_LIST);		
		
	}
	public Resolution  searchArticleList()
	{ 
		articles =articleService.searchArticleList();
		return new ForwardResolution(VIEW_LIST);
		
	}
	
	public Resolution  searchArticleById()
	{ 
		System.out.println(this.getId());
	
		article =articleService.searchArticleById(this.getId());
		
		return new ForwardResolution(VIEW_ARTICLE);
		
	}
	

	public Article getArticle() {
		return article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}

	public List<Article> getArticles() {
		return articles;
	}

	public void setArticles(List<Article> articles) {
		this.articles = articles;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	
	
	
}
